package com.dalao.root.system.config;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里数据源配置，控制台查看
 *
 */
@Configuration
public class DuriConfiguration {
    @Bean
    public ServletRegistrationBean statViewServle(){
        //注册StatViewServlet，访问路径为 /duri
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/durid/*");
        servletRegistrationBean.addInitParameter("jmxUsername","durid");
        servletRegistrationBean.addInitParameter("jmxPassword","durid");
        //设置ip白名单
        servletRegistrationBean.addInitParameter("allow","192.168.1.192,127.0.0.1");
        servletRegistrationBean.addInitParameter("resetEnable","false");
        return servletRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean statFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
        //过滤所有请求
        filterRegistrationBean.addUrlPatterns("/*");
        //忽略过滤格式
        filterRegistrationBean.addInitParameter("exclusions","*.js,*.css,*.gif,*.jpg,*.png,*.ico,/durid/*");
        return filterRegistrationBean;
    }
}
